<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="content-type" content="text/html; charset=utf-8">
	<title>Fancytree - Example: Forms</title>

	<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css">
	<script src="//code.jquery.com/jquery-1.12.1.min.js" type="text/javascript"></script>
	<script src="//code.jquery.com/ui/1.11.4/jquery-ui.min.js" type="text/javascript"></script>

	<link href="../src/skin-win7/ui.fancytree.css" rel="stylesheet" type="text/css">
	<script src="../src/jquery.fancytree.js" type="text/javascript"></script>

	<!-- Start_Exclude: This block is not part of the sample code -->
	<link href="../lib/prettify.css" rel="stylesheet">
	<script src="../lib/prettify.js" type="text/javascript"></script>
	<link href="sample.css" rel="stylesheet" type="text/css">
	<script src="sample.js" type="text/javascript"></script>
	<!-- End_Exclude -->

<style type="text/css">
</style>

	<!-- Add code to initialize the tree when the document is loaded: -->
<script type="text/javascript">
	$(function(){
		$("#tree").fancytree({
			checkbox: true,
			selectMode: 2,
			source: [
//                {title: "Item 1 with embedded html: <input type='input' name='node1info'>", key: "node1"},
				{title: "Item 1", key: "node1"},
				{title: "Folder 2", folder: true, expanded: true, key: "node2",
					children: [
						{title: "Sub-item 2.1", key: "node2.1"},
						{title: "Sub-item 2.2", key: "node2.2"}
					]
				},
				{title: "Item 3", key: "node3"}
			]
		});
		$("#tree2").fancytree({
			checkbox: false,
			selectMode: 3,
			source: [
				{title: "Item 1", key: "node1"},
				{title: "Folder 2", folder: true, key: "node2",
					children: [
						{title: "Sub-item 2.1", key: "node2.1"},
						{title: "Sub-item 2.2", key: "node2.2"}
					]
				},
				{title: "Item 3", key: "node3"}
			]
		});
		$("form").submit(function() {
			// Render hidden <input> elements for active and selected nodes
			$("#tree").fancytree("getTree").generateFormElements();
			$("#tree2").fancytree("getTree").generateFormElements();

			alert("POST data:\n" + jQuery.param($(this).serializeArray()));
			// return false to prevent submission of this sample
			return false;
		});
	});
</script>

<!-- Start_Exclude: This block is not part of the sample code -->
<script>
$(function(){
/*
	addSampleButton({
		label: "Generate <input> elements",
		code: function(){
			$("#tree").fancytree("getTree").generateInput();
			$("#tree2").fancytree("getTree").generateInput();
		}
	});
*/
});
</script>
<!-- End_Exclude -->

</head>

<body class="example">
	<h1>Example: Form</h1>
	<!-- Start_Exclude: This block is not part of the sample code -->
	<div class="description">
	These two trees are embedded in a form, together with some standard elements.
	<ul>
	<li>Use TAB key to move the focus between form elements.<br>
		Note that a tree behaves like a single control (like a radio button group)
	<li>Experimental support for <a href="http://www.w3.org/TR/wai-aria/">WAI-ARIA</a>
	<li>The submit handler is hooked to generate hidden checkbox elements for
		selected and active nodes.<br>
		Note that in select mode 3 only the topmost nodes are considered.
	<li>The values are then POSTed to the server (together with the other form elements).
	</ul>
	</div>
	<div>
		<label for="skinswitcher">Skin:</label> <select id="skinswitcher"></select>
	</div>
	<hr>
	<!-- End_Exclude -->
	<!--
	<form action="http://127.0.0.1:8001/submit_data" method="POST">
	 -->
	<form action="/submit_data" method="POST">
		<textarea name="comment"></textarea>
		<br>
		<fieldset>
			<legend>Radioboxes</legend>
			<input type="radio" name="rb1" value="foo" checked> Foo
			<input type="radio" name="rb1" value="bar"> Bar
			<input type="radio" name="rb1" value="baz"> Baz
		</fieldset>
		<br>
		<fieldset>
			<legend>Checkboxes</legend>
			<input type="checkbox" name="cb1" value="John" checked>John
			<input type="checkbox" name="cb1" value="Paul">Paul
			<input type="checkbox" name="cb1" value="George">George
			<input type="checkbox" name="cb1" value="Ringo">Ringo
		</fieldset>
		<br>
		<fieldset>
			<legend>Lists</legend>
			<select name="list1" multiple="multiple">
				<option value="up">Up</option>
				<option value="down">Down</option>
				<option value="charm">Charm</option>
				<option value="strange">Strange</option>
			</select>
		</fieldset>

		Username: <input type="text" name="userName" />
		<br>

		<!-- The name attribute is used by tree.serializeArray()  -->
		<fieldset>
			<legend>Select 1</legend>
			<div id="tree" name="selNodes">
			</div>
		</fieldset>
		<fieldset>
			<legend>Select 2</legend>
			<div id="tree2" name="selNodes2">
			</div>
		</fieldset>

		<input type="submit" value="Send data">
	</form>

	<!-- Start_Exclude: This block is not part of the sample code -->
	<p id="sampleButtons">
	</p>
	<hr>
	<p class="sample-links  no_code">
		<a class="hideInsideFS" href="https://github.com/mar10/fancytree/">Fancytree project home</a>
		<a class="hideOutsideFS" href="#">Link to this page</a>
		<a class="hideInsideFS" href="index.html">Example Browser</a>
		<a href="#" id="codeExample">View source code</a>
	</p>
	<pre id="sourceCode" class="prettyprint" style="display:none"></pre>
	<!-- End_Exclude -->
</body>
</html>
